package test01;

public class Daemon extends Thread {
    private final User copyThread;

    public Daemon(User copyThread) {
        this.copyThread = copyThread;
        this.setDaemon(true); // 设为守护线程
    }
    public void run() {
        try {
            while (copyThread.isAlive()) { // 当拷贝线程存活时持续监控
                int progress = copyThread.getProgress();
                System.out.printf("拷贝进度: %d%%\n", progress);
                Thread.sleep(500);
            }
            System.out.println("文件拷贝完成，守护线程退出");
        } catch (InterruptedException e) {
            System.out.println("守护线程被中断");
        }
    }
}
